function technikaOpenConsole(event) {
	var menuItem = document.getElementById('menu_technikaConsoleToggle');
	var contentBox = document.getElementById('technikaConsoleContentBox');
	var splitter = document.getElementById('technikaConsoleSplitter');

	menuItem.setAttribute('checked', true);
	contentBox.setAttribute('collapsed', false);
	splitter.setAttribute('collapsed', false);

	window.setTimeout('document.getElementById("technikaConsolePrompt").focus()', 100);
}

function technikaCloseConsole(event) {
	var menuItem = document.getElementById('menu_technikaConsoleToggle');
	var contentBox = document.getElementById('technikaConsoleContentBox');
	var splitter = document.getElementById('technikaConsoleSplitter');

	menuItem.setAttribute('checked', false);
	contentBox.setAttribute('collapsed', true);
	splitter.setAttribute('collapsed', true);
}

function technikaToggleConsole(event) {
	var menuItem = document.getElementById('menu_technikaConsoleToggle');
	var contentBox = document.getElementById('technikaConsoleContentBox');
	var splitter = document.getElementById('technikaConsoleSplitter');

	var checked = menuItem.getAttribute('checked') == 'true' ? true : false;

	if (event && event.originalTarget.id != 'menu_technikaConsoleToggle') {
		menuItem.setAttribute('checked', !checked);
		contentBox.setAttribute('collapsed', checked);
		splitter.setAttribute('collapsed', checked);
	} else {
		contentBox.setAttribute('collapsed', !checked);
		splitter.setAttribute('collapsed', !checked);
	}

	if (!checked) {
		document.getElementById('technikaConsolePrompt').focus();
		window.setTimeout('document.getElementById("technikaConsolePrompt").focus()', 100);
	}
}

function technikaEventContentLoad(e) {
	try {
		TH_isSchemeAllowed(function () {
			var bookmarks = TH_getBookmarkList();
			var levels = [[],[],[],[],[],[],[],[],[],[]];

			for (var i = 0; i < bookmarks.length; i++)
				if (TH_isURLBookmarklet(bookmarks[i].url)) {
					var tokens = bookmarks[i].kw.split(',');
					var autorun = false;
					var level = '9';

					for (var z = 0; z < tokens.length; z++) {
						var keyword = TH_trimString(tokens[z]);

						if (keyword == 'autorun') {
							autorun = true;
						}

						var matched = keyword.match(/^level([0-9])$/);
						level = matched?matched[1]:level;

						if (autorun != false && level != '9') {
							break;
						}
					}

					if (autorun) {
						levels[level].push(bookmarks[i]);
					}
				}

			for (var l = 0; l < levels.length; l++) {
				for (var i = 0; i < levels[l].length; i++) {
					TH_getSelectedBrowserWindow().location = levels[l][i].url;
				}
			}
		});
	} catch (e) {};
}

function technikaEventUnload() {
	window.removeEventListener('DOMContentLoaded', technikaEventContentLoad, false);
	window.removeEventListener('unload', technikaEventUnload, false);
}

window.addEventListener('DOMContentLoaded', technikaEventContentLoad, false);
window.addEventListener('unload', technikaEventUnload, false);
